/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var now = new Date();
var nowday = now.format('d');
var nowmonth = now.format('m');
var nowyear = now.format('Y');

var _pageSize = 20;

var northfieldLabel = new Array('单位名称', 'A类监测点', 'B类监测点', 'C类监测点', 'D类监测点',"D类城网监测点","D类农网监测点", '合计');
var northfieldName = new Array("orgName", "A", "B", "C", "D", "DC","DN","total");
var westfieldLabel = new Array('测点名称', '测点编号');
var westfieldName = new Array("name", "code");
var centerfieldLabel = new Array('测点名称', '测点编号', '终端类型', '监测点类型', '电网类型', '电压等级', '电压上限', '电压下限', '通讯类型', '终端地址', '唯一码', 'IP地址',
        '端口', '监测点ID', '组编码', '行政区域码', 'SIM卡号', '通道', '测点位置', '公共名称', '测点地域', '测点位置',  '在线情况',
        '启用情况', '上报情况', '出厂日期', '投运日期', '检验日期', '有效期', '用户名称', '管理人员', '备注');
var centerfieldName = new Array("name", "code", "model", "pointType", "pointType2", "voltageLevelName", "upperLimit", "lowerLimit", "commTypeName", "terminalNo"
        , "uniqueCode", "ip", "port", "zbm", "adminAreaCode", "mobileNo", "channel", "installSite", "publicName", "pointdy"
        , "model", "pointPosition", "isOffline", "startStatusCh", "reportStatusCh", "produceTime", "runTime", "checkTime", "expireTime", "userName", "realName", "note"
        );
        
        
 var reportStatusStore = new Ext.data.SimpleStore({
    fields: ['id', 'reportName'],
    data: [[0, '观测'], [1, '上报'], [-1, '全部']]
});

var reportCombo = {
    name: 'reportStatus',
    id: 'ReportStatus',
    xtype: 'combo',
    fieldLabel: '上报状态',
    width: 125,
    triggerAction: 'all',
    emptyText: '请选择上报状态...',    
    hiddenName: 'reportStatus',
    editable: false,
    store: reportStatusStore,
    displayField: 'reportName',
    valueField: 'id',
    mode: 'local',
    listeners: {
        select: function(combo, record, index) {
            store.baseParams.reportStatus = combo.getValue();
            pointStore.baseParams.reportStatus = combo.getValue();
        }
    }
};


var rangeStore = new Ext.data.SimpleStore({
    fields: ['id', 'range'],
    data: [[0, '母口径'], [1, '子口径'], [-1, '全口径']]
});

var rangeCombo = {
    name: 'range',
    id: 'Range',
    xtype: 'combo',
    fieldLabel: '口径',
    width: 125,
    triggerAction: 'all',
    emptyText: '统计口径...',    
    hiddenName: 'range',
    editable: false,
    store: rangeStore,
    displayField: 'range',
    valueField: 'id',
    mode: 'local',
    listeners: {
        select: function(combo, record, index) {
            store.baseParams.range = combo.getValue();
            pointStore.baseParams.range = combo.getValue();
        }
    }
};       
 
var store = new Ext.data.JsonStore({
    url: "../../servlet/system/PointLoad",
    root: 'data',
    idProperty: 'orgCode',
    totalProperty: 'count',
    fields: northfieldName,
    autoLoad: true,
    baseParams:{cmd:"number4",type:1,dateTo:now.format("Ymd"),start:0,limit:99}
});

var northcolModel = new Ext.grid.ColumnModel({
    columns: [
        {
            header: northfieldLabel[0],
            width: '100%',
            dataIndex: northfieldName[0],
            align: 'center'
        },
        {
            header: northfieldLabel[1],
            width: '100%',
            dataIndex: northfieldName[1],
            align: 'center'
        },
        {
            header: northfieldLabel[2],
            width: '100%',
            dataIndex: northfieldName[2],
            align: 'center'
        },
        {
            header: northfieldLabel[3],
            width: '100%',
            dataIndex: northfieldName[3],
            align: 'center'
        },
        {
            header: northfieldLabel[4],
            width: '100%',
            dataIndex: northfieldName[4],
            align: 'center'
        },
        {
            header: northfieldLabel[5],
            width: '100%',
            dataIndex: northfieldName[5],
            align: 'center'
        },
        {
            header: northfieldLabel[6],
            width: '100%',
            dataIndex: northfieldName[6],
            align: 'center'
        },
        {
            header: northfieldLabel[7],
            width: '100%',
            dataIndex: northfieldName[7],
            align: 'center'
        }

    ],
    defaultSortable: true
});


var pointStore = new Ext.data.JsonStore({
    url: "../../servlet/system/PointLoad",
    root: 'data',
    idProperty: 'id',
    totalProperty: 'count',
    fields: centerfieldName,
    autoLoad: true,
    baseParams:{cmd:"displayPoint",type:1,dateTo:now.format("Ymd"),start:0,limit:_pageSize} 
});

var centercolModel = new Ext.grid.ColumnModel({
    columns: [
        {
            header: centerfieldLabel[0],
            width: '100%',
            dataIndex: centerfieldName[0],
            align: 'center'
        },
        {
            header: centerfieldLabel[1],
            width: '100%',
            dataIndex: centerfieldName[1],
            align: 'center'
        },
        {
            header: centerfieldLabel[2],
            width: '100%',
            dataIndex: centerfieldName[2],
            align: 'center'
        },
        {
            header: centerfieldLabel[3],
            width: '100%',
            dataIndex: centerfieldName[3],
            align: 'center'
        },
        {
            header: centerfieldLabel[4],
            width: '100%',
            dataIndex: centerfieldName[4],
            align: 'center'
        },
        {
            header: centerfieldLabel[5],
            width: '100%',
            dataIndex: centerfieldName[5],
            align: 'center'
        },
        {
            header: centerfieldLabel[6],
            width: '100%',
            dataIndex: centerfieldName[6],
            align: 'center'
        },
        {
            header: centerfieldLabel[7],
            width: '100%',
            dataIndex: centerfieldName[7],
            align: 'center'
        },
        {
            header: centerfieldLabel[8],
            width: '100%',
            dataIndex: centerfieldName[8],
            align: 'center'
        },
        {
            header: centerfieldLabel[9],
            width: '100%',
            dataIndex: centerfieldName[9],
            align: 'center'
        },
        {
            header: centerfieldLabel[10],
            width: '100%',
            dataIndex: centerfieldName[10],
            align: 'center'
        },
        {
            header: centerfieldLabel[11],
            width: '100%',
            dataIndex: centerfieldName[11],
            align: 'center'
        },
        {
            header: centerfieldLabel[12],
            width: '100%',
            dataIndex: centerfieldName[12],
            align: 'center'
        },
        {
            header: centerfieldLabel[13],
            width: '100%',
            dataIndex: centerfieldName[13],
            align: 'center'
        },
        {
            header: centerfieldLabel[14],
            width: '100%',
            dataIndex: centerfieldName[14],
            align: 'center'
        },
        {
            header: centerfieldLabel[15],
            width: '100%',
            dataIndex: centerfieldName[15],
            align: 'center'
        },
        {
            header: centerfieldLabel[16],
            width: '100%',
            dataIndex: centerfieldName[16],
            align: 'center'
        },
        {
            header: centerfieldLabel[17],
            width: '100%',
            dataIndex: centerfieldName[17],
            align: 'center'
        },
        {
            header: centerfieldLabel[18],
            width: '100%',
            dataIndex: centerfieldName[18],
            align: 'center'
        },
        {
            header: centerfieldLabel[19],
            width: '100%',
            dataIndex: centerfieldName[19],
            align: 'center'
        },
        {
            header: centerfieldLabel[20],
            width: '100%',
            dataIndex: centerfieldName[20],
            align: 'center'
        },
        {
            header: centerfieldLabel[21],
            width: '100%',
            dataIndex: centerfieldName[21],
            align: 'center'
        },
        {
            header: centerfieldLabel[22],
            width: '100%',
            dataIndex: centerfieldName[22],
            align: 'center'
        },
        {
            header: centerfieldLabel[23],
            width: '100%',
            dataIndex: centerfieldName[23],
            align: 'center'
        },
        {
            header: centerfieldLabel[24],
            width: '100%',
            dataIndex: centerfieldName[24],
            align: 'center'            
        },
        {
            header: centerfieldLabel[25],
            width: '100%',
            dataIndex: centerfieldName[25],
            align: 'center'
        },
        {
            header: centerfieldLabel[26],
            width: '100%',
            dataIndex: centerfieldName[26],
            align: 'center'
        },
        {
            header: centerfieldLabel[27],
            width: '100%',
            dataIndex: centerfieldName[27],
            align: 'center'
        },
        {
            header: centerfieldLabel[28],
            width: '100%',
            dataIndex: centerfieldName[28],
            align: 'center'
        },
        {
            header: centerfieldLabel[29],
            width: '100%',
            dataIndex: centerfieldName[29],
            align: 'center'
        },
        {
            header: centerfieldLabel[30],
            width: '100%',
            dataIndex: centerfieldName[30],
            align: 'center'
        },
        {
            header: centerfieldLabel[31],
            width: '100%',
            dataIndex: centerfieldName[31],
            align: 'center'
        }
    ],
    defaultSortable: true
});

var typeCombo = {
    xtype: 'combo',
    width: 80,
    mode: 'local',
    value: 1,
    allowBlank: false,
    id: 'DateTypeCombo',
    triggerAction: 'all',
    forceSelection: true,
    store: new Ext.data.ArrayStore({
        fields: [
            'type',
            'name'
        ],
        data: [[1, '日'], [2, '月'], [3, '年'], [4, '季度']]
    }),
    valueField: 'type',
    displayField: 'name',
    anchor: '50%',
    listeners: {
        select: function(com, records, options) {
            var combo = com.getValue();
            store.baseParams.type = combo;
            pointStore.baseParams.type = combo;
            switch (combo)
            {
                case 1:
                    Ext.getCmp("DateTo").setVisible(true);
                    Ext.getCmp("DateTo").format="Y年m月d日";
                    Ext.getCmp("DateTo").reset();
                    Ext.getCmp("QuarterCombo").setVisible(false);
                    break
                case 2:
                    Ext.getCmp("DateTo").setVisible(true);
                    Ext.getCmp("DateTo").format="Y年m月";
                    Ext.getCmp("DateTo").reset();
                    Ext.getCmp("QuarterCombo").setVisible(false);
                    break;
                case 3:
                    Ext.getCmp("DateTo").setVisible(true);
                    Ext.getCmp("DateTo").format="Y年";
                    Ext.getCmp("DateTo").reset();
                    Ext.getCmp("QuarterCombo").setVisible(false);
                    break;
                case 4:
                    Ext.getCmp("DateTo").setVisible(true);
                    Ext.getCmp("DateTo").format="Y年";
                    Ext.getCmp("DateTo").reset();
                    Ext.getCmp("QuarterCombo").setVisible(true);
                    break;
            }
        }
    }
};
var quarterCombo = {
    xtype: 'combo',
    width: 80,
    mode: 'local',
    value: 1,
    allowBlank: false,
    id: 'QuarterCombo',
    triggerAction: 'all',
    forceSelection: true,
    hidden:true,
    store: new Ext.data.ArrayStore({
        fields: [
            'id',
            'quarter'
        ],
        data: [[1, '第一季度'], [2, '第二季度'], [3, '第三季度'], [4, '第四季度']]
    }),
    valueField: 'id',
    displayField: 'quarter',
    anchor: '50%',
    listener: {
        select: function(o, records, options) {
            store.baseParams.quarterId = o.getValue();
            pointStore.baseParams.quarterId = o.getValue();
        }
    }
};
var northgrid = new Ext.grid.GridPanel({
    title: currentOrgName+' 测点分布汇总',
    width: '100%',
    height: 200,
    region: 'north',
    store: store,
    colModel: northcolModel,
    tbar: new Ext.Toolbar([
        {
            text: "时间单位：",
            xtype: 'label',
            style: {
                marginLeft: '20px'
            }
        },
        typeCombo,
        '-',
        {
            text: "日期：",
            xtype: 'label',
            style: {
                marginLeft: '20px'
            }
        },
        {
            xtype: 'datefield',
            id: 'DateTo',            
            width: 150,
            value: now,            
            format:"Y年m月d日",
            listeners: {
                select: function(c, date) {                    
                    store.baseParams.dateTo = c.getValue().format('Ymd');
                }
            }
        },
        quarterCombo,
        '-',
        reportCombo,
        rangeCombo,
        '-',
        {
            xtype: 'button',
            text: '搜索',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: function() {
                store.reload();
                pointStore.reload();
            }
        }
    ])
});
var centergrid = new Ext.grid.GridPanel({
    width: '80%',
    region: 'center',
    store: pointStore,
    colModel: centercolModel
});

var centerPanel = new Ext.Panel({
    title: currentOrgName+' 测点详细列表',
    layout: 'border',
    width: '100%',
    region: 'center',
    items: [
        centergrid
    ],
    bbar: new Ext.PagingToolbar({
        pageSize: _pageSize,
        store: pointStore,
        displayInfo: true,
        displayMsg: '显示记录：{0} - {1}   总记录：{2}',
        emptyMsg: "目前没有信息"
    })

});

function buildWindow() {

    var applicationUI = new Ext.Viewport({
        layout: 'border',
        items: [
            northgrid, centerPanel
        ]
    });
}
Ext.onReady(buildWindow);  